package definite.Guide.Book.LayoutManager;

import java.awt.Component;
import java.awt.Container;
import java.awt.EventQueue;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JButton;
import javax.swing.JFrame;

public class GridBagButton {

	private static final Insets insect = new Insets(0, 0, 0, 0);

	public static void main(String[] args) {
		Runnable r = new Runnable() {

			@Override
			public void run() {
				JFrame.setDefaultLookAndFeelDecorated(true);
				JFrame frame = new JFrame("GridBagLayout Example");
				frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				frame.setLayout(new GridBagLayout());
				JButton button;
				// Row One - Three Buttons
				button = new JButton("One");
				addComponent(frame, button, 0, 0, 1, 1,
						GridBagConstraints.CENTER, GridBagConstraints.BOTH);
				button = new JButton("Two");
				addComponent(frame, button, 1, 0, 1, 1,
						GridBagConstraints.CENTER, GridBagConstraints.BOTH);
				button = new JButton("Three");
				addComponent(frame, button, 2, 0, 1, 1,
						GridBagConstraints.CENTER, GridBagConstraints.BOTH);
				// Row Two - Two Buttons
				button = new JButton("Four");
				addComponent(frame, button, 0, 1, 2, 1,
						GridBagConstraints.CENTER, GridBagConstraints.BOTH);
				button = new JButton("Five");
				addComponent(frame, button, 2, 1, 1, 2,
						GridBagConstraints.CENTER, GridBagConstraints.BOTH);
				// Row Three - Two Buttons
				button = new JButton("Six");
				addComponent(frame, button, 0, 2, 1, 1,
						GridBagConstraints.CENTER, GridBagConstraints.BOTH);
				button = new JButton("Seven");
				addComponent(frame, button, 1, 2, 1, 1,
						GridBagConstraints.CENTER, GridBagConstraints.BOTH);

				frame.setSize(500, 200);
				frame.setLocationRelativeTo(null);
				frame.setVisible(true);

			}
		};

		EventQueue.invokeLater(r);
	}

	private static void addComponent(Container container, Component component,
										int gridx, int gridy, int gridWidth,
										int gridHeight, int anchor, int fill) {
		GridBagConstraints gbc =
			new GridBagConstraints(gridx, gridy, gridWidth, gridHeight, 1, 1,
					anchor, fill, insect, 0, 0);

	}
}
